/**
 * @description 生成sequelize实例，操作数据库
 * @author malin
 */

const Sequelize = require('sequelize')
const { MYSQL_CONF } = require('../conf/db')
const { isPrd, isTest } = require('../utils/env')

const { database, host, port, user, password } = MYSQL_CONF

// sequelize配置
let seq_conf = {
    host,
    dialect: 'mysql'
}  

// if (isPrd) {
//     // 线上环境使用数据库连接池
//     seq_conf.pool = {
//         max: 5,
//         min: 0,
//         idle: 10000
//     }
// }

// 测试环境下，不打印sql语句
if (isTest) {
    seq_conf.logging = () => {}
}

// 创建sequelize实例
const sequelize = new Sequelize(database, user, password, seq_conf)

module.exports = sequelize
